package com.CGFrame.struts.action.categorySet;

import java.util.Iterator;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Catemodel;
import com.CGFrame.struts.POJOs.Company;
import com.CGFrame.struts.bean.company.CompanyBean;

public class ShowModelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		String companyId = (String)session.getAttribute("CompanyID");
		
		Company c=CompanyBean.getCompanyById(Integer.valueOf(companyId));
//		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
//		Company c = (Company)pop.UniqueQuery("Company", "companyId,"+companyId);
		LinkedList modelset=new LinkedList();
		if(request.getParameter("ganttrelation")!=null){
			for(Iterator iter=c.getCatemodels().iterator();iter.hasNext();){
				Catemodel cm=(Catemodel)iter.next();
				if(cm.getCateModelType().equals(request.getParameter("Type")) || cm.getCateModelType().equals(request.getParameter("modeltype")) || cm.getCateModelType().equals(request.getParameter("cateModelType"))){
					modelset.add(cm);
					request.setAttribute("gantttype", cm.getCateModelType());
				}
			}
			request.setAttribute( "models", modelset );
		}else{
			request.setAttribute( "models", c.getCatemodels());
		}
		return mapping.findForward("showmodel");
	}
}
